<template>
  <a-modal
    title="新增失信人"
    centered
    :visible="true"
    @cancel="dialogClosed"
  >

    <a-form
      :form="form"
    >
      <a-form-item label="失信人名称" class="label-width-auto" v-bind="formItemLayout">
        <a-input
          v-decorator="[
            'studentName',
            { rules: [{ required: true, message: '请输入失信人名称' }] },
          ]"
          placeholder="请输入"
        />
      </a-form-item>
      <a-form-item label="失信人学号" class="label-width-auto" v-bind="formItemLayout">
        <a-input
          v-decorator="[
            'studentNo',
            { rules: [{ required: true, message: '请输入失信人学号' }] },
          ]"
          placeholder="请输入"
        /></a-form-item>
      <a-form-item label="所属年级" class="label-width-auto" v-bind="formItemLayout">
        <a-select
          v-decorator="[
            'gradeId',
            { rules: [{ required: true, message: '请选择' }] },
          ]"
          placeholder="请选择"
          @change="handleChange"
        >
          <a-select-option
            v-for="item in departmentList"
            :key="item.deptId"
            :value="item.deptId"
          >
            {{ item.deptName }}
          </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="家长姓名" class="label-width-auto" v-bind="formItemLayout">
        <a-input
          v-decorator="[
            'parentName',
            { rules: [{ required: true, message: '请输入家长姓名' }] },
          ]"
          placeholder="请输入"
        />
      </a-form-item>
      <a-form-item label="联系方式" class="label-width-auto" v-bind="formItemLayout">
        <a-input
          v-decorator="[
            'parentMobile',
            { rules: [{ required: true, message: '请输入联系方式' }] },
          ]"
          placeholder="请输入"
        />
      </a-form-item>
      <a-form-item label="失信原因" class="label-width-auto" v-bind="formItemLayout">

        <a-textarea
          v-decorator="[
            'reason',
            { rules: [{ required: true, message: '请输入失信原因' }] },
          ]"
          placeholder="请输入"
        />
      </a-form-item>
    </a-form>
    <span slot="footer" class="dialog-footer">
      <a-button @click="dialogClosed()">取消</a-button>
      <a-button id="submit" :loading="submitButton.status" type="primary" @click="dataFormSubmit()">{{ submitButton.text }}</a-button>
    </span>
  </a-modal>
</template>

<script>
import { edit } from '@/pages/blacklist/api/blacklist'
export default {
  name: 'BlacklistSave',
  inject: ['formItemLayout'],
  props: {
    data: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      dataForm: {
        id: null
      },
      submitButton: {
        text: '提交',
        status: false
      },
      departmentList: []
    }
  },
  mounted () {
    this.$gradeListFunc().then(data => {
      this.departmentList = data
    })
    // 处理不在表单中的字段
    this.form.getFieldDecorator('gradeName', { initialValue: null, preserve: true })
  },
  methods: {
    dialogClosed () {
      this.$emit('dialogClosed')
    },
    // 表单提交
    dataFormSubmit () {
      this.$saveQuit('form', edit)
    },
    handleChange (value) {
      this.departmentList.forEach(depart => {
        if (value === depart.deptId) {
          this.form.setFieldsValue({ gradeName: depart.deptName })
        }
      })
    }

  }
}
</script>
